package homework.service.iml;

import homework.entity.Goods;
import homework.entity.User;
import homework.mapper.GoodsMapper;
import homework.mapper.UserMapper;
import homework.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author :黄靓仔
 * @description: TODO
 * @data :2020/8/14 13:57
 */
@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    GoodsMapper goodsMapper;

    @Autowired
    UserMapper userMapper;

    @Override
    public List<Goods> queryAll() {
        return goodsMapper.queryAll();
    }
    @Override
    public void addGoods(Goods goods) { //管理员增加系统没有的商品
        goodsMapper.addGoods(goods);
    }

    @Override
    public void changeGoodsNum(String goodsName, Integer num) { //管理员可以改变商品货存
        Goods goods=goodsMapper.queryByName(goodsName);
        goodsMapper.changeGoodsNum(goodsName, num+goods.getInventory());
    }

    @Override
    public void changeGoodsFlag(String goodsName , Integer flag) {  //管理员下架商品或者上架商品
        goodsMapper.changeGoodsFlag(goodsName, flag);
    }

    @Override
    public void buy(String goodsName ,String inventory) {      //用户买商品后该库存减少
    }
    //@Override
   /* public int getGoodsFlag(String goodsName) {    //根据名字返回商品姓名
       return goodsMapper.queryByName(goodsName).getFlag();
    }*/
}
